package com.aotain.common;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import net.sf.json.JSONObject;

public class DBConfigInit {
//   
//    private String ips;
    
    private String _mushroomServer;
    
    private DBObject _obj = new DBObject();
    
	public DBConfigInit(String dbConfig) 
	{
//		System.out.println("dbconfig:" + dbConfig);
	    
	    try {   
	    	Properties prop = new Properties();   
		    InputStream in = new FileInputStream(dbConfig);
	        prop.load(in);   
	       
	        
//	        ips = prop.getProperty("ips").trim(); 
	        		
	        _obj.setName(prop.getProperty("name"));
	        _obj.setType(prop.getProperty("type"));
	        _obj.setMaxActive(prop.getProperty("maxActive"));
	        _obj.setMaxIdle(prop.getProperty("maxIdle"));
	        _obj.setMaxWait(prop.getProperty("maxWait"));
	        _obj.setValidationQuery(prop.getProperty("validationQuery"));
	        _obj.setQueryTimeout(prop.getProperty("queryTimeout"));
	        _obj.setDriverClassName(prop.getProperty("driverClassName"));
	        _obj.setUrl(prop.getProperty("url"));
	        _obj.setUserName(prop.getProperty("username"));
	        _obj.setPassword(prop.getProperty("password"));
	        
//	        _obj.setDbdriver(prop.getProperty("dbdriver"));
//	        _obj.setDburl(prop.getProperty("dburl"));
//	        _obj.setDbuser(prop.getProperty("dbuser"));
//	        _obj.setDbpassword(prop.getProperty("dbpassword"));
	        
	        _mushroomServer = prop.getProperty("mushroomserver").trim(); 
	        
	        //postfix = prop.getProperty("postfix").trim();  
	        
	        //System.out.println("######filter url postfix:" + postfix);
	        
	    } catch (IOException e) {   
	        e.printStackTrace();   
	    }   
    }
	
//	public String getIPs()
//	{
//		return this.ips;
//	}
	
	public String getMushroomServer()
	{
		return this._mushroomServer;
	}
	
	public String getDBObjectJson()
	{
		JSONObject json = JSONObject.fromObject(_obj);
		return json.toString();
	}
	
	public DBObject getDBObj() {
		return _obj;
	}
}
